

#include <gtk/gtk.h>
#include <stdio.h>
#include "support.h"
#include "window.h"
#include "dialog.h"
#include "help.h"
#include "gsim.h"

/*################ help about ###################*/
void gsim_help_about(void)
{

	GtkWidget *about_dialog;//,*a_label,*gsim_label,*mean_label,*copy_label,*gsim_image;

	about_dialog=gtk_about_dialog_new();
	//gtk_widget_set_parent(about_dialog,gsim_appwindow);
	const gchar *authers[3]={ "Vinod Kumar Dahiya <dahiyavinod@gmail.com>","Hemant Kumar<hemantkumar1982@gmail.com>",NULL};
	const gchar *documenters[3]={ "Vinod Kumar Dahiya <dahiyavinod@gmail.com>","Hemant Kumar<hemantkumar1982@gmail.com>",NULL};
	
	gchar *label=
	"      This program is free software; you can redistribute it "
	"and/or modify it under the terms of the GNU General "
	"Public License as published by the Free Software "
	"Foundation; either version 2 of the License, or "
	"(at your option) any later version.\n"
	"      This program is distributed in the hope that it will "
	"be useful, but WITHOUT ANY WARRANTY; without even the "
	"implied warranty of MERCHANTABILITY or FITNESS FOR A "
	"PARTICULAR PURPOSE.  See the GNU General Public License "
	"for more details.\n"	
	"      You should have received a copy of the GNU General "
	"Public License along with this program; if not, write "
	"to the Free Software Foundation, Inc., 675 Mass Ave, "
	"Cambridge, MA 02139, USA.";
	
/*	g_object_set(G_OBJECT(about_dialog),"program-name","GSim85","version","0.1",
				                        "comments","An 8085 Microprocessor Simulator",
				                         "copyright","Vinod Dahiya & Hemant Kumar",
				                         "website","http://sourceforge.net/projects/gsim85",
				 						"website-label","http://sourceforge.net/projects/gsim85",
				 						"license",label,"wrap-license",TRUE,
				                         "documenters",documenters,
				                         "authors",authers,NULL);*/
    gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(about_dialog),"GSim85");
    gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(about_dialog),"0.2");
    gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(about_dialog),"An 8085 Microprocessor Simulator");
    gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(about_dialog),"Vinod Dahiya & Hemant Kumar");
    gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(about_dialog),"http://gsim85.sourceforge.net");
    gtk_about_dialog_set_website_label(GTK_ABOUT_DIALOG(about_dialog),"http://gsim85.sourceforge.net");
    gtk_about_dialog_set_license(GTK_ABOUT_DIALOG(about_dialog),label);
    gtk_about_dialog_set_wrap_license(GTK_ABOUT_DIALOG(about_dialog),TRUE);
    gtk_about_dialog_set_documenters(GTK_ABOUT_DIALOG(about_dialog),documenters);
    gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(about_dialog),authers);
    
    
	gtk_dialog_run (GTK_DIALOG (about_dialog));
	gtk_widget_destroy(about_dialog);
//#endif	
}

/*################ How to report bugs #################*/
void gsim_report_bugs(void)
{
	GtkWidget *dialog,*label;
	dialog=gtk_dialog_new_with_buttons("Report Bugs",GTK_WINDOW(gsim_appwindow),
											GTK_DIALOG_DESTROY_WITH_PARENT,GTK_STOCK_OK,GTK_RESPONSE_NONE,NULL);
	
	label=gtk_label_new(_("\n\tWrite the complete description of the context in\t \n"
						"\twhich the program is misbehaving and mail to:\n\n" 
						"\tEmail : <span foreground=\"NavyBlue\" font_desc=\"luxi sans  9\"><u>bugs@sinew.in</u></span>\n"));
	gtk_label_set_use_markup(GTK_LABEL(label),TRUE);
	gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox),label);
	
	g_signal_connect(dialog,"response",G_CALLBACK(gtk_widget_destroy),dialog);
	gtk_widget_show_all(dialog);
}

/*################ How to report bugs #################*/
void gsim_geting_involve(void)
{
	GtkWidget *dialog,*label;
	dialog=gtk_dialog_new_with_buttons(_("Geting Involved"),GTK_WINDOW(gsim_appwindow),
											GTK_DIALOG_DESTROY_WITH_PARENT,GTK_STOCK_OK,GTK_RESPONSE_NONE,NULL);
	
	label=gtk_label_new(_("\n\tGSim85 is open for young developers. If you\t \n"
						"\tenhance certain function or develope new one.\n" 
						"\tPlease notify us at :\n\n"
						"\tEmail : <span foreground=\"NavyBlue\" font_desc=\"luxi sans  9\"><u>ideas@sinew.in</u></span>\n"));
	gtk_label_set_use_markup(GTK_LABEL(label),TRUE);
	gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox),label);
	
	g_signal_connect(dialog,"response",G_CALLBACK(gtk_widget_destroy),dialog);
	gtk_widget_show_all(dialog);
}

/*############### License Info #################*/
void gsim_license(void)
{
	GtkWidget *dialog,*text_view;
	GtkTextBuffer *buffer;
	gchar *label;
	dialog=gtk_dialog_new_with_buttons(_("LICENSE"),GTK_WINDOW(gsim_appwindow),
											GTK_DIALOG_DESTROY_WITH_PARENT,NULL);
	
	label=
	"                  PROJECT : GSim85 ( A 8085 Simulator )         \n"
	"                  E-MAIL  : info@sinew.in                          \n"
	"                                                                      		\n"
	"                Copyright (c) SINEW SOFTWARE SYSTEMS             \n"
	"__________________________________________________________	\n"
	"\n"	
 	"\n"
	"==================================================	\n"
	"  This program is free software; you can redistribute it              	\n"
	"  and/or modify it under the terms of the GNU General                 \n"
	"  Public License as published by the Free Software                    \n"
	"  Foundation; either version 2 of the License, or                     	\n"
	"  (at your option) any later version.                                 	\n"
	"                                                                      			\n"
	"  This program is distributed in the hope that it will                	\n"
	"  be useful, but WITHOUT ANY WARRANTY; without even the     \n"
	"  implied warranty of MERCHANTABILITY or FITNESS FOR A           \n"
	"  PARTICULAR PURPOSE.  See the GNU General Public License 	\n"
	"  for more details.                                                  \n"	
	"                                                                      	\n"
	"  You should have received a copy of the GNU General         \n"
	"  Public License along with this program; if not, write            \n"
	"  to the Free Software Foundation, Inc., 675 Mass Ave,             \n"
	"  Cambridge, MA 02139, USA.                                          \n"
	"==================================================	";
	
	text_view=gtk_text_view_new();
	buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
    gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text_view),10);
	gtk_text_view_set_editable(GTK_TEXT_VIEW(text_view),FALSE);
	gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(text_view),FALSE);
	gtk_text_view_set_justification(GTK_TEXT_VIEW(text_view),GTK_JUSTIFY_LEFT);
	gtk_text_buffer_set_text(buffer,label,g_utf8_strlen(label,-1));
	gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox),text_view);
	
	g_signal_connect(dialog,"response",G_CALLBACK(gtk_widget_destroy),dialog);
	gtk_widget_show_all(dialog);
}

/*################## help about the application #################*/
void gsim_contents(void)
{
	GtkWidget *a_dialog,*sw;
	
	a_dialog=gtk_dialog_new_with_buttons(_("Help"),GTK_WINDOW(gsim_appwindow),
												GTK_DIALOG_DESTROY_WITH_PARENT,
												NULL);
	gtk_widget_set_size_request(a_dialog,-1,400);
	
	GtkWidget *view;
  	GtkTextBuffer *buffer;
  	view = gtk_text_view_new ();
  	buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
    gtk_text_view_set_left_margin(GTK_TEXT_VIEW(view),10);
	gtk_text_view_set_right_margin(GTK_TEXT_VIEW(view),10);
	gtk_text_view_set_justification(GTK_TEXT_VIEW(view),GTK_JUSTIFY_LEFT);
	gtk_text_view_set_editable(GTK_TEXT_VIEW(view),FALSE);
	gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(view),FALSE);
	
	 sw = gtk_scrolled_window_new (NULL, NULL);
     gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
				      GTK_POLICY_NEVER,
				      GTK_POLICY_AUTOMATIC);
	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),GTK_SHADOW_IN);
    gtk_container_add (GTK_CONTAINER (sw), view);
	
	gchar *tch;
#ifdef G_OS_WIN32
    tch = g_build_filename (package_help_dir, "use.txt", NULL);
#else	
    tch = g_build_filename (PACKAGE_HELP_DIR, "use.txt", NULL);
#endif

	FILE *use_file;
	gchar c;
	GString *text;
//	if((use_file=fopen(PACKAGE_HELP_DIR"/use.txt","r"))==NULL)
    if((use_file=fopen(tch,"r"))==NULL)
	{
		gsim_message(_("Can't open Help File."),GTK_MESSAGE_ERROR);
		g_free(tch);
		return;
	}
	g_free(tch);
	
	text=g_string_new("");
	while((c=fgetc(use_file))!=EOF )
		g_string_append_c(text,c);
	gtk_text_buffer_set_text (buffer, text->str, -1);
	
	gtk_container_add(GTK_CONTAINER(GTK_DIALOG(a_dialog)->vbox),sw);
	g_signal_connect(a_dialog,"response",G_CALLBACK(gtk_widget_destroy),a_dialog);
	gtk_widget_show_all(a_dialog);
}
